package com.yunxi.controller.com;

import com.alibaba.dubbo.config.annotation.Reference;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.sys.service.ToolDubboService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/admin/tool")
@Api(tags = "sys:tool", description = "工具接口")
public class ToolController {

    @Autowired
    ToolDubboService toolDubboService;

    @GetMapping("/exist6")
    @ApiOperation(value = "查询是否重复")
    public Object exist6(@RequestParam Map<String, Object> map) throws Exception {
        return ResponseUtil.ok(toolDubboService.exist6(map));
    }

    @GetMapping("/exist")
    @ApiOperation(value = "查询是否重复")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="query", name = "tableName", value = "表名", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "colKey", value = "字段名", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "colValue", value = "字段值", required = true, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "where", value = "位置", required = false, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "idName", value = "主键字段名", required = false, dataType = "String"),
            @ApiImplicitParam(paramType="query", name = "idValue", value = "主键字段名", required = false, dataType = "String")
    })
    public Object exist(String tableName, String colKey, String colValue, String where,String idName,String idValue) throws Exception {
        return ResponseUtil.ok(toolDubboService.exist(tableName, colKey, colValue, where,idName,idValue));
    }

    @GetMapping("/exist2")
    @ApiOperation(value = "查询双字段是否重复")
    public Object exist2(@RequestParam(value = "tableName") String tableName, @RequestParam String colKey, @RequestParam String colValue, @RequestParam String colKey2, @RequestParam String colValue2, @RequestParam String where) throws Exception {
        return ResponseUtil.ok(toolDubboService.exist2(tableName, colKey, colValue,colKey2, colValue2,where));
    }

    @GetMapping("/dict_list")
    @ApiOperation(value = "查询是否重复")
    public Object dict_list(@RequestParam(value = "tableName") String tableName, @RequestParam String dictKey, @RequestParam String dictValue, @RequestParam String where) throws Exception {
        return ResponseUtil.ok(toolDubboService.dict_list(tableName, dictKey, dictValue,where));
    }
}